﻿Public Class FormNewRoom
    Dim DARoom As New DSFloorManagemantTableAdapters.ROOMSTableAdapter
    Dim DAFloor As New DSFloorManagemantTableAdapters.FLOORSTableAdapter
    Dim DACategory As New DSFloorManagemantTableAdapters.ROOM_CATEGORYTableAdapter
    Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        With CboCategoryRoom
            .DataSource = DACategory.GetData
            .ValueMember = "CATEGORY_ID"
            .DisplayMember = "GATEGORY_NAME"
            .SelectedIndex = -1
        End With
        With CboFloor
            .DataSource = DAFloor.GetData
            .ValueMember = "FLOOR_ID"
            .DisplayMember = "FLOOR_NAME"
            .SelectedIndex = -1
        End With
        ' Add any initialization after the InitializeComponent() call.

    End Sub
    Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
        Me.Close()
    End Sub

    Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        If ValidateTextField(TxtRoomName, "", ErrorProvider1) = False Then Exit Sub
        If ValidateCombobox(CboCategoryRoom, "", ErrorProvider1) = False Then Exit Sub
        If ValidateCombobox(CboFloor, "", ErrorProvider1) = False Then Exit Sub
        If ValidateTextField(TxtBed, "", ErrorProvider1) = False Then Exit Sub
        If ValidateTextField(TxtBed, "", ErrorProvider1) = False Then Exit Sub
        If LblSaveOption.Text = "0" Then
            If MessageBox.Show("Do you want to save new room?", "Room", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                If DARoom.NewRooms(CboFloor.SelectedValue, CboCategoryRoom.SelectedValue, TxtRoomName.Text, TxtBed.Text, TxtDescriptRoom.Text) = 1 Then
                    MessageBox.Show("Save new room successfull.", "Room", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    Me.DialogResult = Windows.Forms.DialogResult.OK
                Else
                    MessageBox.Show("Eorror save new room successfull.", "Room", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            End If
        Else
            If MessageBox.Show("Do you want to update room?", "Room", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                If DARoom.UpdateRoomInfo(CboFloor.SelectedValue, CboCategoryRoom.SelectedValue, TxtRoomName.Text, TxtBed.Text, TxtDescriptRoom.Text, LblSaveOption.Text) = 1 Then
                    MessageBox.Show("Update room successfull.", "Room", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    Me.DialogResult = Windows.Forms.DialogResult.OK
                Else
                    MessageBox.Show("Eorror Update room successfull.", "Room", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            End If
        End If
    End Sub

    Private Sub TxtBed_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtBed.KeyPress
        SetDisableKeyString(e)
    End Sub
End Class